package com.czt.mail.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.czt.mail.kafka.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author czt
 * @version 1.0
 * {@desc}
 * @date 2024/10/8 18:33
 */
@RestController
public class HelloController {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/hello")
    public String hello() {
        //kafkaTemplate.send("czt-topic", "czt");
        User user = new User();
        user.setName("czt");
        user.setSex("男");
        kafkaTemplate.send("czt-topic", JSON.toJSONString(user));
        return "ok";
    }
}
